import React from 'react';
import ReactDOM from 'react-dom';
import '../../static/tero/pop.less';
import $ from 'jquery';
import { Upload, Icon, Modal } from 'antd';

// 弹框组件

class Pop extends React.Component{
    constructor(props){
        super(props)
        this.state = {
            flag:2,
            display:'none',
            list:[{index:0,title:'提示',content:'是否需要加入样本？'},
            {index:1,title:'删除',content:'是否需要删除这条信息?'},
            {index:2,title:'研判',content:'确定要将这条信息研判为案件吗？'},
            {index:0,title:'提示',content:'确定要清空选中的信息么？'},
            {index:0,title:'提示',content:'请先选择信息后再进行操作'},
            {index:0,title:'提示',content:'是否需要加入样本？'},
            {index:0,title:'提示',content:'是否需要删除这条信息?'},
            {index:0,title:'提示',content:'确定将信息导出么?'},
            {index:0,title:'提示',content:'确定将信息已阅么?'},
            {index:2,title:'研判',content:'确定要将这条信息研判为舆情吗？'},
            {index:2,title:'研判',content:'确定要将这条信息研判为情报吗?'},
            {index:0,title:'提示',content:'公众号：<input id="addWeixin" type="text" placeholder="请输入公众号"/>'},
            {index:0,title:'提示',content:''}]
        }
        this.handleClick = this.handleClick.bind(this);
    }
    
    componentWillMount(){
        this.setState((prevState, props)=>({
            display:this.props.display
        }))      
    }
    componentDidMount(){
        $(window).resize(function () {          
           $('.pop').css({height:document.body.offsetHeight,width:document.body.offsetWidth})
        });
    }
    
    handleClick=()=>{
      let that=this;
      const input=document.getElementById('upload');
          $('.pic').parent().find(".upload").click(); //隐藏了input:file样式后，点击头像就可以本地上传
            $('.pic').parent().find(".upload").on("change",function(){
            var objUrl = that.getObjectURL(input.files[0]) ; //获取图片的路径，该路径不是图片在本地的路径
            
            if (objUrl) {
              $('.pic').parent().find(".example").attr("src", objUrl) ; //将图片路径存入src中，显示出图片
            }
          });
     
    }
   getObjectURL=(file)=> {
      var url = null ;
      // alert(file);
      if (window.createObjectURL!=undefined) { // basic
          url = window.createObjectURL(file) ;
      } else if (window.URL!=undefined) { // mozilla(firefox)
          url = window.URL.createObjectURL(file) ;
      } else if (window.webkitURL!=undefined) { // webkit or chrome
          url = window.webkitURL.createObjectURL(file) ;
      }
      return url ;
  }

    render(){
        return (
            <div className='pop' style={{height:document.body.offsetHeight,width:document.body.offsetWidth,display:this.props.display}}>
                <div className='popson' >
                 <div className='popson_son' style={{position:'relative'}}>
                 {/* {
                    this.state.list[this.props.index].index == 0? <img src={require('../../static/image/pop_icon1.png')} alt=""/>:(this.state.list[this.props.index].index == 1?<img src={require('../../static/image/pop_icon2.png')}/>:<img src={require('../../static/image/pop_icon3.png')}/>)
                 } */}
                           
                            <span className='ti'>{this.state.list[this.props.index].title}</span>
                            <img onClick={()=>{this.props.colse('none')}} src={require('../../static/image/X_nor.png')} alt="" style={{position:'absolute',right:'0px',top:'8px',cursor:'pointer'}}/>
                            {/* 判断上传文件是否有内容 */}
                            {
                              this.state.list[this.props.index].content ? <p dangerouslySetInnerHTML={{__html:this.state.list[this.props.index].content}}></p> :  <p>
                              上传群二维码：
                               <span className="pic" onClick={this.handleClick
                               } ></span>
                               <input id='upload' className="upload" type="file" style={{display: 'none'}}/>
                               <img className='example' />
                              </p>
                            }
                            {/* <p dangerouslySetInnerHTML={{__html:this.state.list[this.props.index].content}}></p> */}
                            <div className='btn'><span onClick={()=>{this.props.colse('none')}}>取消</span><span onClick={()=>{this.props.colse('none',this.props.index)}}>确定</span></div>
                        </div>: <div></div>   
                </div>
            </div>
        )
    }
}


export default Pop